package main

import "fmt"

// 产品接口（Vehicle 表示车辆，可以是汽车，也可以是单车）
type Vehicle interface {
	Drive()
}

// 产品实现
type Car struct{}

func (c *Car) Drive() {
	fmt.Println("Driving a car.")
}

type Bike struct{}

func (b *Bike) Drive() {
	fmt.Println("Riding a bike.")
}

// 简单工厂
type VehicleFactory struct{}

func (vf *VehicleFactory) CreateVehicle(vehicleType string) Vehicle {
	switch vehicleType {
	case "car":
		return &Car{}
	case "bike":
		return &Bike{}
	default:
		return nil
	}
}

func main() {
	factory := &VehicleFactory{}
	car := factory.CreateVehicle("car")
	bike := factory.CreateVehicle("bike")

	car.Drive()  // 输出: Driving a car.
	bike.Drive() // 输出: Riding a bike.
}
